﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Pozr
{
    public partial class ControlSettings : UserControl
    {
        public void AddLabel(String text)
        {
            Label label = new Label();
            label.Text = text;
            label.Font = new Font(FontFamily.GenericSansSerif, 10.0f, FontStyle.Bold);
            label.TextAlign = ContentAlignment.TopCenter;
            label.Dock = DockStyle.Top;
            label.ForeColor = Color.White;
            label.Height = 40;
            this.Controls.Add(label);
            label.BringToFront();
        }

        public void AddCheckBox(String group, String text)
        {
            CheckBox cb = new CheckBox();
            cb.Text = text;
            cb.Dock = DockStyle.Top;
            cb.ForeColor = Color.White;
            cb.Height = 40;
            cb.Checked = (bool)Middleware.Settings.GetSetting(group, text);
            cb.CheckStateChanged += delegate {
                Middleware.Settings.SetSetting(group, text, cb.Checked);
            };
            this.Controls.Add(cb);
            cb.BringToFront();
        }

        public void InitControls()
        {
            foreach (String g in Middleware.Settings.GetSettingGroups())
            {
                if (Middleware.Settings.GetSettings(g).Count > 0)
                {
                    AddLabel(g);
                    foreach (KeyValuePair<String, object> s in Middleware.Settings.GetSettings(g))
                    {
                        if (s.Value != null)
                        {
                            if (s.Value.GetType().Name == "Boolean")
                            {
                                AddCheckBox(g, s.Key);
                            }
                        }
                    }
                }
            }
        }

        public ControlSettings()
        {
            InitializeComponent();
        }
    }
}
